<?php
require_once('message.php');
require_once dirname(__DIR__) . '../message/ALIDAYU/api_sdk/vendor/autoload.php';

use Aliyun\Core\Config;
use Aliyun\Core\Profile\DefaultProfile;
use Aliyun\Core\DefaultAcsClient;
use Aliyun\Api\Sms\Request\V20170525\SendSmsRequest;

// 加载区域结点配置
Config::load();

class ALIDAYU implements MessageInterface{
    public function send_message( $mobile, $content ){
        preg_match('/\d{6}/', $content, $matches);
        $mobile_code = $matches[0];

        $accessKeyId = "LTAIh3L4EeHWvxLz";//参考本文档步骤2
        $accessKeySecret = "43mWZOorK9neZCmoGfVEQSLyoTQiQK";//参考本文档步骤2
        $product = "Dysmsapi";
        $domain = "dysmsapi.aliyuncs.com";
        $region = "cn-hangzhou";
        $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
        DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", $product, $domain);
        $acsClient= new DefaultAcsClient($profile);

        $request = new SendSmsRequest;
        $request->setPhoneNumbers($mobile);
        $request->setSignName("明易科技");
        $request->setTemplateCode("SMS_92180015");
        $request->setTemplateParam("{\"code\":\"$mobile_code\"}");
        $acsResponse = $acsClient->getAcsResponse($request);

        if($acsResponse->Message =="OK"){
            return true;
        } else {
            return false;
        }

    }

}
